$(function(){
	$('#do_upload').submit(function (e){
		$('#waiter').show();
		e.preventDefault();
		$.ajaxFileUpload({
			url	: './do_upload',
			secureuri:	false,
			fileElementId:	'userfile',
			dataType:	'json',
			success  : function (data)
	         {
				$('#waiter').hide();
				//if uploaded image has geo location meta data
	            if(data.status == 'success')
	            {
	            	$('input[name=lat]').val(data.lat);
		            $('input[name=lon]').val(data.lon);
		            initialize(data.lat,data.lon);
		            $("#close-reveal-modal").trigger("click");
	            }
	            
	            else if(data.status == 'nogeo'){
	            	$('#uploadError').empty();
	            	$("#uploadError").append(data.msg);
	            	$("#uploadError").css("color", "red");

	            }
	            
	            else{
	            	//alert(data.msg);
	            	$('#uploadError').empty();
	            	$("#uploadError").append(data.msg);
	            	$("#uploadError").css("color", "red");
	            }
	            
	         }	
		});
		return false;
	});
});